package com.lwl.blog.controller;

import com.alibaba.fastjson.JSON;
import com.lwl.blog.core.servlet.BaseServlet;
import com.lwl.blog.entity.InvitataionEntity;
import com.lwl.blog.entity.UserEntity;
import com.lwl.blog.service.InvitationService;
import com.lwl.blog.service.impl.InvitationServiceImpl;

import javax.servlet.annotation.WebServlet;


@WebServlet("/InvitationServlet/*")
public class InvitationServlet extends BaseServlet {
   private InvitationService invitationService=new InvitationServiceImpl();

   public String publish() throws Exception{
       //1.获取用户信息
       UserEntity loginUser = (UserEntity) req.getSession().getAttribute("loginUser");
       if (loginUser==null){
           return outJson(100,"登录超时，请重新登陆!");
       }

       //2.读取前端数据
       String s = req.getReader().readLine();
       InvitataionEntity invitataionEntity = JSON.parseObject(s, InvitataionEntity.class);

       //3.封装用户信息
       invitataionEntity.setUserId(loginUser.getId());
       boolean save = invitationService.save(invitataionEntity);

       return outJson(save);

   }
}
